﻿//-----------------------------------------------------------------------
// <copyright file="Behavior.cs" company="tuliprules.org">
//     Copyright (c) 2011 tuplelister, tuliprules.org.
// </copyright>
// <summary>This is the Behavior class.</summary>
//-----------------------------------------------------------------------
namespace Tulip.Rules.Models.Rif.Prd
{
    using System;
    using System.ComponentModel;
    using System.Xml.Serialization;

    /// <summary>
    /// Represents a nested collection of sentences.
    /// </summary>
    [Serializable]
    [DesignerCategory(@"code")]
    [XmlType(AnonymousType = true, Namespace = "http://www.w3.org/2007/rif#")]
    [XmlRoot(Namespace = "http://www.w3.org/2007/rif#", IsNullable = false)]
    public class Behavior : IRifPrdElement
    {
        /// <summary>
        /// The conflictResolution field.
        /// </summary>
        [EditorBrowsable(EditorBrowsableState.Never)]
        private string conflictResolutionField;

        /// <summary>
        /// The priority field.
        /// </summary>
        [EditorBrowsable(EditorBrowsableState.Never)]
        private int priorityField;

        /// <summary>
        /// Gets or sets behaviour of the rule engine.
        /// </summary>
        [XmlElement(Order = 0)]
        public string ConflictResolution
        {
            get
            {
                return this.conflictResolutionField;
            }

            set
            {
                if (!Uri.IsWellFormedUriString(value, UriKind.RelativeOrAbsolute))
                {
                    throw new Exception(string.Format("RIF PRD conflict resolution specifiers must be well-formed URIs.  Attempt to assign value of {0}.", value));
                }

                this.conflictResolutionField = value;
            }
        }

        /// <summary>
        /// Gets or sets behaviour of the rule engine.
        /// </summary>
        [XmlElement(Order = 1)]
        public int Priority
        {
            get
            {
                return this.priorityField;
            }

            set
            {
                if (value > 10000 || value < -10000)
                {
                    throw new Exception(string.Format("RIF PRD accepts priority values in the range of -10000 to 10000.  Attempt to assign value of {0}.", value));
                }

                this.priorityField = value;
            }
        }
    }
}
